#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Create by zhang
# Create on 2022/6/25 7:33
from typing import Tuple

from domain.report.common.period_enum import PeriodEnum
from infrastructure.util.dateutils import get_current_year


def get_pre_period(year:int, period:PeriodEnum) -> Tuple[int, PeriodEnum]:
    if year > get_current_year() or year < 2010 or not period or not isinstance(period, PeriodEnum):
        return (None, None)
    enum_ins_dict = PeriodEnum.get_instance_dict()
    if enum_ins_dict.keys()[0] == period.name:
        return (year-1, enum_ins_dict[-1])
    else:
        for i, key in enumerate(enum_ins_dict.keys()):
            if key == period.name:
                return (year, enum_ins_dict[i-1])